package test1;

import java.util.Objects;

class Money implements Cloneable{
    public int money;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    // 自己重写一个equals方法
    /*@Override
    public boolean equals(Object obj) {
        Student tmp = (Student)obj;

        // 要同一中类型的才能比较,应该都为子类对象
        // return this.name.equals(obj.name);
        return this.name.equals(tmp.name) &&
                this.age == tmp.age;
    }*/
}
public class test11 {

    public static void main(String[] args) {
        Student person = new Student("张三",20);
        Student person1 = new Student("张三",20);

        System.out.println(person.equals(person1));
    }
    public static void main1(String[] args) throws CloneNotSupportedException{
        Person person = new Person("张三",20);

        Person person2 = (Person)person.clone();// clone

        System.out.println(person2);
        System.out.println(person);
    }
}
